import 'package:flutter/material.dart';

import 'package:aweb5/base/BaseWidget.dart';

import 'package:aweb5/util/HttpUtils1.dart';
import 'package:aweb5/util/HttpClient.dart';
import 'package:aweb5/util/WindowUtil.dart';

import 'package:aweb5/config/Config.dart';

import 'package:flutter/cupertino.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'AplusHomePage.dart';
import 'dart:async';
import 'StartPage.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:aweb5/util/DialogUtil.dart';
import 'Agreement1.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/services.dart';
class NaviPage extends StatefulWidget {
  @override
  State<NaviPage> createState() => _NaviPageState();
}

class _NaviPageState extends State<NaviPage> {
  List<String> image = List();
  int index = 0;
  NeverScrollableScrollPhysics neverScrollableScrollPhysics =
      NeverScrollableScrollPhysics();
  dynamic temp = ScrollPhysics();
  var timer;
  NavigatorState navigatorState;
  @override
  void initState() {
    super.initState();
//    timer = new Timer(const Duration(milliseconds: 1500), () {
//      try {
//        Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(
//            builder: (BuildContext context) => new HomePage()), (//跳转到主页
//            Route route) => route == null);
//      } catch (e) {
//
//      }
//    });

    image.add("assets/second.jpg");
    image.add("assets/third.jpg");
    image.add("assets/first.jpg");

//        else{
//
//        }

    WidgetsBinding.instance.addPostFrameCallback((Duration duration) {
      print(">>>post");

//        if(v==null){

      DialogUtil.showdialog(
          context,
          WillPopScope(child:
          Column(
            children: <Widget>[
              Text("个人信息保护指引",style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold),),
              Expanded(child: SingleChildScrollView(
                child: Html(
                  data: """
    <!--For a much more extensive example, look at example/main.dart-->
     
    <p>1. 在浏览使用时，我们会使用您的设备标识信息用于推荐。</p>
<p>2. 我们可能会使用您的位置信息，为您推荐附近的服务，但不会收集和存储任何精确位置信息。</p>
<p>3. 您可以查看完整版<a href="https://h5.hhnry.com/agreement.html">《用户协议》</a>和<a href="https://h5.hhnry.com/agreement1.html">《隐私政策》</a>以便了解我们使用您手机信息的情况，以及对信息的保护措施。</p>
<br>
<br>
    <p>如果您同意请点击下面的按钮以接收我们的服务。</p>
     
  """,
                  //Optional parameters:
                  padding: EdgeInsets.all(8.0),
                  backgroundColor: Colors.white70,
                  defaultTextStyle: TextStyle(fontFamily: 'serif'),
                  linkStyle: const TextStyle(
                    color: Colors.redAccent,
                  ),
                  onLinkTap: (url) {
                    if(url=="https://h5.hhnry.com/agreement.html"){
                      navigatorState.push(new MaterialPageRoute(builder: (con){return
                        Agreement1("xiyi");
                      }));
                    }else{
                      navigatorState.push(new MaterialPageRoute(builder: (con){return
                        Agreement1("p");
                      }));
                    }
//                      launch(url);
                    // open url in a webview
                  },
                  onImageTap: (src) {
                    // Display the image in large form.
                  },
                  //Must have useRichText set to false for this to work.
                ),
              ))
              ,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  InkWell(
                    child: Center(
                      child: Center(
                        child: Text(
                          "暂不使用",
                          style: TextStyle( fontSize: 18),
                        ),
                      ),
                    ),
                    onTap: (){
                      SystemChannels.platform.invokeMethod('SystemNavigator.pop');
                    },
                  )
                  ,
                  InkWell(
                    child: Center(
                      child: Text(
                        "同意",
                        style: TextStyle(color: Color(0xffFF5B00), fontSize: 18),
                      ),
                    ),
                    onTap: () {
                      navigatorState.pop();
                      setFirst();
                    },
                  )
                ],
              )

            ],
          ), onWillPop: (){
            SystemChannels.platform.invokeMethod('SystemNavigator.pop');
          })
          ,
          450);
    });
  }
  setFirst()async{
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setBool("first", false);
  }
  @override
  Widget build(BuildContext context) {
    navigatorState = Navigator.of(context);
    return Scaffold(
      body:
//        new Container(
//            width: MediaQuery.of(context).size.width,
//            height: MediaQuery.of(context).size.height,
//            color: Color.fromRGBO(0, 0, 0, 0),
//            child: Image.asset("assets/start.jpg",fit: BoxFit.fill,)

          new Swiper(
        itemBuilder: (BuildContext context, int index) {
          return new InkWell(
            child: Image.asset(image[index],
                fit: BoxFit.fill, height: MediaQuery.of(context).size.height),
            onTap: () {
              if (index == 2) {
                Navigator.of(context)
                    .pushReplacement(new MaterialPageRoute(builder: (con) {
                  return new StartPage();
                }));
              }
            },
          );
        },
        itemCount: image.length,
        autoplay: false,
        loop: false,
        onIndexChanged: (int s) {
//               setState(() {});
          index = s;
          if (index == 2) {}
        },
        pagination:
////          new SwiperPagination(builder: SwiperPagination.fraction),
            new SwiperPagination(
                builder: DotSwiperPaginationBuilder(
          color: Colors.transparent,
          activeColor: Colors.transparent,
        )),
      ),

      //  ),

      //  )
    );
  }
}
